#include "../mtcp_module.h"


VCAL::VCAL()
{
	memset(&m_VCAL_REQ, 0, sizeof(m_VCAL_REQ));
	m_pData = nullptr;
}


VCAL::~VCAL()
{
}


int VCAL::NTC_STEADY_STATE(float v)
{
	m_VCAL_REQ.NTC_STEADY_STATE = v;
	return 0;
}
int VCAL::T_STEADY_STATE(float v)
{
	m_VCAL_REQ.T_STEADY_STATE = v;
	return 0;
}
int VCAL::PEAK_OPTICAL_POWER_FINAL(float v)
{
	m_VCAL_REQ.PEAK_OPTICAL_POWER_FINAL = v;
	return 0;
}
int VCAL::I_PULSE_FINAL(float v)
{
	m_VCAL_REQ.I_PULSE_FINAL = v;
	return 0;
}
int VCAL::V_PULSE_FINAL(float v)
{
	m_VCAL_REQ.V_PULSE_FINAL = v;
	return 0;
}
int VCAL::PEAK_WAVELENGTH(float v)
{
	m_VCAL_REQ.PEAK_WAVELENGTH = v;
	return 0;
}

int VCAL::setvalue(char *what, char* value)
{
	if (0 == strcmp(what, "NTC_STEADY_STATE")){
		NTC_STEADY_STATE(atof(value));
		return 0;
	}
	if (0 == strcmp(what, "T_STEADY_STATE")){
		T_STEADY_STATE(atof(value));
		return 0;
	}
	if (0 == strcmp(what, "PEAK_OPTICAL_POWER_FINAL")){
		PEAK_OPTICAL_POWER_FINAL(atof(value));
		return 0;
	}
	if (0 == strcmp(what, "I_PULSE_FINAL")){
		I_PULSE_FINAL(atof(value));
		return 0;
	}
	if (0 == strcmp(what, "V_PULSE_FINAL")){
		V_PULSE_FINAL(atof(value));
		return 0;
	}
	
	if (0 == strcmp(what, "PEAK_WAVELENGTH")){
		PEAK_WAVELENGTH(atof(value));
		return 0;
	}
	if (0 == strcmp(what, "FWHM_WAVELENGTH")){
		FWHM_WAVELENGTH(atof(value));
		return 0;
	}
	if (0 == strcmp(what, "WL_DATA_LEN")){
		WL_DATA_LEN(atoi(value));
		return 0;
	}
	if (0 == strcmp(what, "ITER_CNT")){
		ITER_CNT(atoi(value));
		return 0;
	}


	return -1;
}

int VCAL::FWHM_WAVELENGTH(float v)
{
	m_VCAL_REQ.FWHM_WAVELENGTH = v;
	return 0;
}
int VCAL::WL_DATA_LEN(int v)
{
	m_VCAL_REQ.WL_DATA_LEN = v;
	return 0;
}
int VCAL::ITER_CNT(int v)
{
	m_VCAL_REQ.ITER_CNT = v;
	return 0;
}

int VCAL::pushData(float I, float v, float power, const char * v_pulse_raw, float power_raw)
{
	return 0;
}


int VCAL::SendVCAL()
{
	int ret = SendFrame(kMTCP_CTRL_VCAL, &m_VCAL_REQ, sizeof(m_VCAL_REQ), m_pData, m_VCAL_REQ.ITER_CNT);
	tMTCP_payload_TEST_RSP rep;
	int recv_cnt = RecvResponse(&rep, sizeof(rep));
	return ret;
}